package com.example.todo;


import static android.content.Context.NOTIFICATION_SERVICE;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;


public class AlarmReceiver extends BroadcastReceiver {


    //定义通知标题和内容，避免魔法字符串
    public static String title = "ToDo";
    public static String content = "content";
    public static String news = "您设置的ToDo开始时间到啦";

    @Override
    public void onReceive(Context context, Intent intent) {
        //将设置好的标题的内容取出来
        SharedPreferences sp = context.getSharedPreferences("notif", context.MODE_PRIVATE);
        title = (sp.getString("Title", title));
        content = (sp.getString("Content", content));

        //初始调用
        NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
        Notification.Builder builder = new Notification.Builder(context);
        builder.setSmallIcon(R.drawable.notif);
        builder.setContentTitle(title);
        builder.setContentText(content);
        builder.setTicker(news);
        builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.logo));
        builder.setContentInfo("附加消息");
        //全部效果展示(震动，铃声，呼吸灯)
        builder.setDefaults(Notification.DEFAULT_ALL);
        //点击页面跳转
        intent = new Intent(context, MainActivity.class);
        PendingIntent activity = PendingIntent.getActivity(context, 100, intent, PendingIntent.FLAG_ONE_SHOT);
        builder.setContentIntent(activity);
        //悬浮显示
        builder.setFullScreenIntent(activity, true);
        manager.notify(1, builder.build());
    }
    //传递通知

}